package com.example.delayqueue.consumer;

import com.example.delayqueue.config.DelayedQueueConfig;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @version 1.0.0
 * @className: DelayedConsumer
 * @description: 延迟队列消费者
 * @author: LiJunYi
 * @create: 2022/8/4 13:34
 */
@Component
@Slf4j
public class DelayedConsumer
{
    @RabbitListener(queues = DelayedQueueConfig.DELAYED_QUEUE_NAME)
    public void receiveMsg(Message message, Channel channel){
        String msg = new String(message.getBody());
        log.info("当前时间为{}，收到延迟消息为{}",new Date(), msg);
    }
}
